{include file="common/_header-css"}
{include file="common/_jQuery"}
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">员工列表</a>
            <a>
              <cite>员工管理</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="search"  placeholder="请输入用户名&&账号" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" id="button_search" type="button"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加用户','{:url(\'member/member_add\')}',600,600)"><i class="layui-icon"></i>添加用户</button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                    <th>ID</th>
                                    <th>员工号</th>
                                    <th>用户名</th>
                                    <th>性别</th>
                                    <th>所属部门</th>
                                    <th>级别</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                  </tr>
                                </thead>
                                <tbody>
                                {volist name="userList" id="vo"}
                                  <tr>
                                    <td>{$vo.id}</td>
                                    <td>{$vo.account}</td>
                                    <td>{$vo.username}</td>
                                    <td>{if $vo.sex == 1}男{else /}女{/if}</td>
                                    <td>{$vo.department_name}</td>
                                    <td>{$vo.related_level.level_name}</td>
                                    <td class="td-status">
                                        {if $vo.status == 1}
                                        <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                                        {else /}
                                        <span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">已停用</span>
                                        {/if}
                                    </td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'{$vo.id}')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','{:url(\'member/memberUpdateStatus\')}?id={$vo.id}',600,600)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'{$vo.id}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                {$userList|raw}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;

      });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用/启用吗？',function(index){
              if($(obj).parents("tr").find(".td-status").find('span').hasClass('layui-btn-disabled')){
                  $.post('{:url(\'member/memberUpdateStatus\')}?type=1',{id:id,status:1},function (res) {
                      if (res.code == 200) {
                          $(obj).attr('title','启用')
                          $(obj).find('i').html('&#xe601;');

                          $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                          layer.msg('已启用!',{icon: 6,time:1000});
                      }else{
                          layer.msg(res.msg,{icon:5,time:500});
                      }
                  });
              }else{
                  $.post('{:url(\'member/memberUpdateStatus\')}?type=1',{id:id,status:2},function (res) {
                      if (res.code == 200) {
                          $(obj).attr('title','停用')
                          $(obj).find('i').html('&#xe62f;');

                          $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                          layer.msg('已停用!',{icon: 5,time:1000});
                      }else{
                          layer.msg(res.msg,{icon:5,time:500});
                      }
                  });
              }
          });
      }
      $('#button_search').click(function () {
          let search = $('input[name=\'search\']').val();
          if (search == '')
          {
              layer.msg('搜索关键字不能为空!',{icon: 6,time:500});
              return false;
          }else{
              location.href='{:url(\'member/member_search\')}?search='+search;
          }
      });

      function member_del(Obj,id) {
          layer.alert('您确定要删除吗?',function () {
              $.post('{:url(\'member/delete\')}',{id:id},function (res) {
                  if (res.code == 200) {
                      layer.msg(res.msg,{icon: 6,time:500},function () {
                          location.reload();
                      });
                  }else{
                      layer.msg(res.msg,{icon: 5,time:500});
                  }
              });

          })
      }
    </script>
</html>